# -*- encoding: utf-8 -*-
"""
    Created by Rachel on 2025/03/06
"""
from functools import wraps

from flask import jsonify


def fail_api(msg):
    return jsonify({"code": 1, "message": msg})


def success_api(msg="请求成功", result=None):
    return jsonify({"code": 0, "message": msg, "result": result if result else {}})


def error(func):
    @wraps(func)
    def __wrapper__(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            return fail_api(msg="{}".format(e))

    return __wrapper__